﻿using DevExpress.XtraEditors;
using DevExpress.XtraGrid;
using MesProjectWinform.Production.Common;
using MesProjectWinform.Production.Models;
using MesProjectWinform.Public;
using MesProjectWinform.Public.Common;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace MesProjectWinform.Production.Forms.ProductLock
{
    public partial class LockReasonForm : DevExpress.XtraEditors.XtraForm
    {
        public LockReasonForm()
        {
            InitializeComponent();
        }

        ProductLockInput model = new ProductLockInput();

        public void GetData(ProductLockInput input)
        {
            model.PRODUCTLOCKCODE = input.PRODUCTLOCKCODE;
            model.PRODUCTLOCKTYPE = input.PRODUCTLOCKTYPE;
            model.PRODUCTLOCKPRODUCTION = input.PRODUCTLOCKPRODUCTION;
            model.PRODUCTLOCKBEGINTIME = input.PRODUCTLOCKBEGINTIME;
            model.PRODUCTLOCKENDTIME = input.PRODUCTLOCKENDTIME;
        }

        private async void simpleButton2_Click(object sender, EventArgs e)
        {
            model.LOCKINGREASON = memoEdit1.Text.Trim();
            var json = JsonConvert.SerializeObject(model);
            var response = await HttpClientHelper.RequestUrl(RequestType.Post, ProductionGolab.ProductionLock, json);
            var apiResult = JsonConvert.DeserializeObject<ApiResult<int>>(response);
            if (apiResult.Code == ApiEnums.Success)
            {
                MessageBox.Show($"{apiResult.Message}");
                GlobalEvents.RaiseProductUnLockRefresh(); // 触发刷新
                this.DialogResult = DialogResult.OK; // 设置对话框结果为OK
                this.Close(); // 关闭当前窗口
            }
            else
            {
                MessageBox.Show($"{apiResult.Message}");
            }
        }
    }
}